﻿using ETModel;
using System;
using UnityEngine;

namespace ETHotfix {
    [MessageHandler]
    public class M2C_GizmosDebugHandler : AMHandler<M2C_GizmosDebug> {
        protected override void Run(ETModel.Session session, M2C_GizmosDebug message) {
            if (GizmosDebug.Instance == null) return;

            foreach (var item in message.AddGizmosMeshs) {
                GizmosDebug.Instance.AddUnitMesh(item.Key, item.GetVertices(), item.GetIndices(), item.GetCenterPosition(), item.GetRotation(), item.GetScale());
            }
            foreach (var removeId in message.RemoveGizmosMeshs) {
                GizmosDebug.Instance.RemoveUnitMesh(removeId);
            }

            foreach (var item in message.AddRayTestLine) {
                GizmosDebug.Instance.AddUnitRayTest(item.Key, new Vector3(item.StartX, item.StartY, item.StartZ), new Vector3(item.EndX, item.EndY, item.EndZ)
                    , new Color(item.ColorR, item.ColorG, item.ColorB));
            }
            foreach (var removeId in message.RemoveRayTestLine) {
                GizmosDebug.Instance.RemoveUnitRayTest(removeId);
            }
        }
    }
}
